<?php

namespace app\util;

/*
 * 地址类
 */
use think\Cache;
use think\Db;

class Address
{
    /*
     * 获取省份名称
     */
    public static function getProvinceName($province_id)
    {
        $key = 'province_' . $province_id;

        $name = Cache::get($key);
        if ($name) {
            return $name;
        } else {
            $name = Db::name('prov_city_area')->where('id', '=', $province_id)->value('name');

            Cache::set($key, $name);

            return $name;
        }
    }

    /*
     * 获取城市名称
     */
    public static function getCityName($city_id)
    {
        $key = 'city_' . $city_id;

        $name = Cache::get($key);
        if ($name) {
            return $name;
        } else {
            $name = Db::name('prov_city_area')->where('id', '=', $city_id)->value('name');

            Cache::set($key, $name);

            return $name;
        }
    }

    /*
     * 获取地区名称
     */
    public static function getAreaName($area_id)
    {
        $key = 'area_' . $area_id;

        $name = Cache::get($key);
        if ($name) {
            return $name;
        } else {
            $name = Db::name('prov_city_area')->where('id', '=', $area_id)->value('name');

            Cache::set($key, $name);

            return $name;
        }
    }



}